// pages/video/video.js
import { getViedoList, getVideoListPromise, getBannerList, getBannerListPromise } from "../../utils/api.js"

Page({
  /**
   * 页面的初始数据
   */
  data: {
    
    slideShow: false,
    slideRatio: '',
    navArray:[
      {
        catid: 1,
        url:'/pages/list/list?title=品种导航&catid=1',
        src:'../../images/nav_logo_1.png',
        title: "品种导航"
      },
      {
        catid: 2,
        url: '/pages/list/list?title=庄稼医生&catid=2',
        src: '../../images/nav_logo_2.png',
        title: "庄稼医生"
      },
      {
        catid: 3,
        url: '/pages/list/list?title=菜园机械&catid=3',
        src: '../../images/nav_logo_3.png',
        title: "菜园机械"
      },
      {
        catid: 4,
        url: '/pages/list/list?title=栽培技术&catid=4',
        src: '../../images/nav_logo_4.png',
        title: "栽培技术"
      },
      {
        catid: 5,
        url: '/pages/list/list?title=话农点金&catid=5',
        src: '../../images/nav_logo_5.png',
        title: "话农点睛"
      },
      {
        catid: 6,
        url: '/pages/list/list?title=商业影视&catid=6',
        src: '../../images/nav_logo_6.png',
        title: "商业影视"
      },
      {
        catid: 7,
        url: '/pages/list/list?title=活动策划&catid=7',
        src: '../../images/nav_logo_7.png',
        title: "活动策划"
      },
      {
        url: '/pages/view/view',
        src: '../../images/nav_logo_8.png',
        title: "微视觉"
      },
      {
        url: '/pages/many/many',
        src: '../../images/fenlei.png',
        title: "更多"
      }
    ],
    requsetNum: 4,
    videoList: [],
    bannerList: [],
    isIde: true,
    userInfo: {
      avatarUrl: '../../images/avatar.png'
    }
  },

  storageData: function(data, id){
    // console.log(id)
    var temp = this.data.videoList;
    temp[id-1] = data;
    this.setData({
      videoList: temp
    });
  },
  getData: function(Type){
    // 请求视频新闻
    var that = this;
    getVideoListPromise(this.data.navArray[0].catid, this.data.requsetNum, 1).then(function(data){
      that.storageData(data,that.data.navArray[0].catid)
      return getVideoListPromise(that.data.navArray[1].catid, that.data.requsetNum, 1);
    }).then(function(data){
      that.storageData(data,that.data.navArray[1].catid)
      return getVideoListPromise(that.data.navArray[2].catid, that.data.requsetNum, 1);
    }).then(function(data){
      that.storageData(data, that.data.navArray[2].catid)
      return getVideoListPromise(that.data.navArray[3].catid, that.data.requsetNum, 1);
    }).then(function(data){
      that.storageData(data, that.data.navArray[3].catid)
      return getVideoListPromise(that.data.navArray[4].catid, that.data.requsetNum, 1);
    }).then(function(data){
      that.storageData(data, that.data.navArray[4].catid)
      return getVideoListPromise(that.data.navArray[5].catid, that.data.requsetNum, 1);
    }).then(function(data){
      that.storageData(data, that.data.navArray[5].catid)
      return getVideoListPromise(that.data.navArray[6].catid, that.data.requsetNum, 1);
    }).then(function(data){
      that.storageData(data, that.data.navArray[6].catid)
      return getBannerListPromise(3);
    }).then(function(data){
      that.setData({
        bannerList: data
      });
      if (Type) {
        // 隐藏导航栏加载框
        wx.hideNavigationBarLoading();
        // 停止下拉动作
        wx.stopPullDownRefresh();
      }
    })
  },
  onLoad: function (options) {
  

    wx.showLoading({
      title: '加载中',
    });
    this.getData();
    if (wx.getStorageSync('userInfo')){
      this.setData({
        isIde:  false,
        userInfo: wx.getStorageSync('userInfo')
      })
    }
  },
 
  onReady: function () {
    wx.hideLoading();
  },
  onPullDownRefresh: function(){
    wx.showNavigationBarLoading();
    this.getData(true)
  },

  onShareAppMessage: function () {

  },
    getleft(e) {
    //slideLeft动态变化
    this.setData({
      slideLeft: e.detail.scrollLeft * this.data.slideRatio
    })
  } 
})